package com.csk.zsk.compents.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.csk.zsk.commons.entity.IdEntity;
import com.google.common.collect.Lists;

@Entity
@Table(name = "RANKING_LIST")
// 此annoation为了截断对象的循环引用.
@JsonIgnoreProperties({ "musicList" })
public class RankingList extends IdEntity {

	private String listName;
	private String listDesc;
	private String imageUrl;
	private List<Music> musicList = Lists.newArrayList();

	public String getListName() {
		return listName;
	}

	public void setListName(String listName) {
		this.listName = listName;
	}

	public String getListDesc() {
		return listDesc;
	}

	public void setListDesc(String listDesc) {
		this.listDesc = listDesc;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	// 多对多定义
	@ManyToMany
	// 中间表定义,表名采用默认命名规则
	@JoinTable(name = "MUSIC_LIST", joinColumns = { @JoinColumn(name = "LIST_ID") }, inverseJoinColumns = { @JoinColumn(name = "MUSIC_ID") })
	// Fecth策略定义
	@Fetch(FetchMode.SUBSELECT)
	// 集合按id排序.
	@OrderBy("id")
	public List<Music> getMusicList() {
		return musicList;
	}

	public void setMusicList(List<Music> musicList) {
		this.musicList = musicList;
	}

}
